export default {

    category: Blockly.Categories.event ,
    
    color: [
        Blockly.Colours.operators.primary,
        Blockly.Colours.operators.secondary,
        Blockly.Colours.operators.tertiary
    ] ,

    previousStatement: false ,
    nextStatement: false ,
    hat: false ,
    eventHandle: false ,

    output: "boolean" ,

    init() {
        this.appendValueInput("OPERAND1")
        this.appendDummyInput()
            .appendField(new Blockly.FieldDropdown(() => {
                return [
                    ['=' , '=='] ,
                    ['<' , '<'] ,
                    ['>' , '>'] ,
                    ['<=' , '<='] ,
                    ['>=' , '>='] ,
                ]
            }), 'OP')
        this.appendValueInput("OPERAND2")
    } ,

    coder: {
        JavaScript(block: any, coder: any) {
            var operator = block.getFieldValue('OP');
            var order = (operator == '==' || operator == '!=') ?
                coder.ORDER_EQUALITY : coder.ORDER_RELATIONAL;
            var argument0 = coder.valueToCode(block, 'OPERAND1', order) || '0';
            var argument1 = coder.valueToCode(block, 'OPERAND2', order) || '0';
            var code = argument0 + ' ' + operator + ' ' + argument1;
            return [code, order];
        }
    }
}
